package com.tjsinfo.tjsoa.address.inside;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.hibernate.Transaction;



/**
 * A data access object (DAO) providing persistence and search support for
 * TAddresslistInside entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.tjsinfo.tjsoa.address.inside.TAddresslistInside
 * @author MyEclipse Persistence Tools
 */

public class TAddresslistInsideDao extends HibernateDaoSupport implements ITAddresslistInsideDao {
	
	private static final Log log = LogFactory
			.getLog(TAddresslistInsideDao.class);
	public void save(TAddresslistInside transientInstance) {
		Session session=getSession();
		Transaction tran=session.beginTransaction();
		log.debug("saving TAddresslistInside instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TAddresslistInside persistentInstance) {
		log.debug("deleting TAddresslistInside instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public void delete(String propertyName, Object value) {
		log.debug("deleting TAddresslistInside instance");
		try {
			String hql="delete TAddresslistInside where "+propertyName+" = "+value;
			getHibernateTemplate().delete(value);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	
	public void update(TAddresslistInside transientInstance) {
		log.debug("saving TAddresslistInside instance");
		try {
			this.getHibernateTemplate().update(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	public List findByID(java.lang.Integer id) {
	    log.debug("finding TAddresslistInside instance with id: "
			+ id );
	    try {
		    String queryString = "from TAddresslistInside as model where model.id = ? order by id desc";
		    return getHibernateTemplate().find(queryString, id);
	    } catch (RuntimeException re) {
		    log.error("find by property name failed", re);
		    throw re;
	    }
	}
	
	public List findByOrganizeId(java.lang.String organizeId) {
	    log.debug("finding TAddresslistInside instance with organizeId: "
			+ organizeId );
	    try {
		    String queryString = "from TAddresslistInside as model where model.organizeId = ? order by id desc";
		    return getHibernateTemplate().find(queryString, organizeId);
	    } catch (RuntimeException re) {
		    log.error("find by property name failed", re);
		    throw re;
	    }
	}
	
	public TAddresslistInside findById(java.lang.Integer id) {
		log.debug("getting TAddresslistInside instance with id: " + id);
		try {
			TAddresslistInside instance = (TAddresslistInside) getHibernateTemplate()
			.get("com.tjsinfo.tjsoa.address.inside.TAddresslistInside", id);
	        return instance;
        } catch (RuntimeException re) {
	        log.error("get failed", re);
	        throw re;
        }
	}
	
	public List findByDepartment(java.lang.String department) {		
		Session session=getSession();
		log.debug("finding TAddresslistInside instance with property: "
				+ department + ", value: " + department );
		try {
			Criteria criteria = getSession().createCriteria(TAddresslistInside.class);
			criteria.add(Expression.eq(department, department));
			criteria.addOrder(Order.desc("id"));
			return criteria.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByExample(TAddresslistInside instance) {
		log.debug("finding TAddresslistInside instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TAddresslistInside instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TAddresslistInside as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	
	public List findByLikeProperty(String likeName, Object value) {
		Session session=getSession();
		log.debug("finding TAddresslistInside instance with property: "
				+ likeName + ", value: " + value);
		try {
			Criteria criteria = session.createCriteria(TAddresslistInside.class);
			criteria.add(Expression.like(likeName, value));
			return criteria.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	
	public List findAll() {
		log.debug("finding all TAddresslistInside instances");
		try {
			String queryString = "from TAddresslistInside";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	
	public List findByLikePropertyAndProperty(String likeName, Object value, String propertyName,Object values) {
		Session session=getSession();
		log.debug("finding TAddresslistInside instance with property: "
				+ likeName + ", value: " + value + ", property:" + propertyName +",value:"+values);
		try {
			Criteria criteria = session.createCriteria(TAddresslistInside.class);
			criteria.add(Expression.like(likeName, value));
			criteria.add(Expression.like(propertyName, values));
			return criteria.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	public List findList(String chineseName, Object value, String department,Object values, String organizeId,Object valuess) {
		Session session=getSession();
		log.debug("finding TAddresslistInside instance with property: "
				+ chineseName + ", value: " + value + ", property:" + department +",value:"+values + ", property:" + organizeId +",value:"+valuess);
		try {
			Criteria criteria = session.createCriteria(TAddresslistInside.class);
			criteria.add(Expression.like(chineseName, value));
			criteria.add(Expression.like(department, values));
			criteria.add(Expression.eq(organizeId, valuess));
			criteria.addOrder(Order.desc("id"));
			return criteria.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
}